package com.example.aidl;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.widget.Toast;

import net.liteheaven.xblib.common.log.XLog;

public class RemoteService extends Service {

	private final static String TAG = RemoteService.class.getSimpleName();

	// action执行在非主线程，想显示toast需要post
	private Handler handler = new Handler(Looper.getMainLooper());
	
	private IRemoteService.Stub mBinder = new IRemoteService.Stub() {
		
		@Override
		public void action() throws RemoteException {
			handler.post(new Runnable() {
				@Override
				public void run() {
					Toast.makeText(getApplicationContext(), "在服务中弹Toast!", Toast.LENGTH_SHORT).show();
				}
			});
			XLog.i(TAG, "action");
		}
	};
	
	public void onCreate() {
		super.onCreate();
		XLog.i(TAG, "onCreate");
	}

	@Override
	public IBinder onBind(Intent intent) {
		XLog.i(TAG, "onBind");
		return mBinder;
	}
}
